var strPath = "{/literal}{$strPath}{literal}";
var strCurrentId = 0;

objUser.checkAuth(function(loggedin){
	if(loggedin == false) {
		document.location = "/login";
	} else {
		jQuery("#blocker").hide();
	}
});

jQuery(function(){

	var strHtml = '<a href="/main">Hauptverzeichniss</a>';

	var aryPathParts = strPath.split("/");

	for(var i = 0; i < aryPathParts.length; i++){
		var strPathTo = "/";
		for(var j = 0; j <= i; j++) {
			if(aryPathParts[j] != "") {
				strPathTo += aryPathParts[j] + "/";
			}
		}

		if(aryPathParts[i] != "") {
			strHtml += " / " + '<a href="/main' + strPathTo + '">' + aryPathParts[i] + '</a>';
		}
	}

	jQuery('#path-box').html(strHtml);

	//load the list
	objFs.loadList({
		path: strPath,
		callback: function(id, html){
			strCurrentId = id;
			jQuery('#list').html(html);
		} 
	});

	jQuery('#new-file-button').click(function(){
		jQuery('#upload-dialog').show();
		jQuery('#upload-dialog').css("left", ((jQuery(window).width() - jQuery('#upload-dialog').width() ) / 2) + "px");
		jQuery('#upload-dialog').css("top", ((jQuery(window).height() - jQuery('#upload-dialog').height() ) / 2) + "px");
	});

	jQuery(window).resize(function(){
		jQuery('#upload-dialog').css("left", ((jQuery(window).width() - jQuery('#upload-dialog').width() ) / 2) + "px");
		jQuery('#upload-dialog').css("top", ((jQuery(window).height() - jQuery('#upload-dialog').height() ) / 2) + "px");
	});

	jQuery('#upload-dialog input[name=file]').change(function(){
		jQuery('#upload-dialog .progress').css("width", "0px");
	});

	jQuery('#upload-dialog #upload-button').click(function(){
		objFs.uploadFile({
			data: {
				"parent_id": strCurrentId
			},
			success: function(data){
				alert("ok!");
				jQuery('#upload-dialog').hide();
			},
			error: function(data){
				alert("error!");
			}
		});
	});

	jQuery('#upload-dialog #cancel-button').click(function(e){
		e.preventDefault();
		jQuery('#upload-dialog').hide();
	});

	/*
	 * Logout Button Click
	 */
	jQuery('#logout-button').click(function(){
		//log out and redirect to /login
		objUser.logout();
	});
});